package com.scaffold.photo.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import wangjg.commons.page.Page;

import com.scaffold.photo.dao.AlbumDAO;
import com.scaffold.photo.entity.Album;

@Service
@Transactional
public class AlbumService {

	@Autowired
	private AlbumDAO albumDAO;

	public Album getAlbum(Long id ) {
		return this.albumDAO.findById(id);
	}

	public void save(Album album){
		Date now = new Date();
		if(album.getId()==null){
			album.setCreated(now);
			album.setModified(now);
			this.albumDAO.save(album);
		}else{
			album.setModified(now);
			this.albumDAO.update(album);
		}
	}

	public void update(Album album){
		Date now = new Date();
		album.setModified(now);
		this.albumDAO.update(album);
	}

	public void delete(Album album){
		this.albumDAO.delete(album);

	}

	public void batchDelete(String idseq) {
		String[] sa = idseq.split(",");
		for(String s:sa){
			Long id = Long.parseLong(s);
			this.albumDAO.delete(id);

		}
	}
	
	public List<Album> pageQuery(Page page, String name, String keyword) {
		return this.albumDAO.pageQuery(page, name, keyword);
	}


}
